



let model = document.querySelector('.model')
let user = document.querySelector('.user')
let userClear = document.querySelector('.userclear')
let pwdClear = document.querySelector('.pwdclear')
let pwd = document.querySelector('.pwd')


let userAlert = document.querySelector('.useralert')
let pwdAlert = document.querySelector('.pwdalert')
let logo = document.querySelector('.logo')
let regist = document.querySelector('.regist')
let logoBox = document.querySelector('.logobox')
let registBox = document.querySelector('.registbox')
let active = document.querySelector('.model .active')
let logoBtn = document.querySelector('.logobtn')
//console.log(btn)

/* 需求:如果user的名字不符合规范,则提示输入错误 */
let userReg = /^(13[0-9]|14[01456879]|15[0-3,5-9]|16[2567]|17[0-8]|18[0-9]|19[0-3,5-9])\d{8}$/
let pwdReg = /^\d{6}$/

//如果账号不是11位数的电话号码,则提示错误
user.addEventListener('blur',function(){
    let bool = userReg.test(user.value)
    if(bool){
        userAlert.style.display = 'none'
        userAlert.textContent = ''
    }else{
        userAlert.style.display = 'block'
        userAlert.textContent = '账号输入不正确'
    }
})
pwd.addEventListener('blur',function(){
    let bool = pwdReg.test(pwd.value)
    if(bool){
        pwdAlert.style.display = ''
        pwdAlert.textContent = ''
    }else{
        pwdAlert.style.display = 'block'
        pwdAlert.textContent = '密码输入不正确'
    }
})

/* 需求: 点击logo,显示logoBox的界面
         点击regist,显示 registBox的界面
*/
logo.addEventListener('click',function(){
    logoBox.style.display = 'block'
    registBox.style.display = 'none'
    regist.classList.remove('active')
    logo.classList.add('active')
})

regist.addEventListener('click',function(){
    logoBox.style.display = 'none'
    registBox.style.display = 'block'
    regist.classList.add('active')
    logo.classList.remove('active')
})


/* 
  需求: user框输入值时,clear显示.
*/

user.addEventListener('input',function(){
    if(user.value.length>0){
        userClear.style.display = 'block'
    }else
        userClear.style.display = 'none'
})
pwd.addEventListener('input',function(){
    if(pwd.value.length>0){
        pwdClear.style.display = 'block'
    }else
        pwdClear.style.display = 'none'
})


/* 需求: 点击userclear,清空user的值,userclear并隐藏 */
userClear.addEventListener('click',function(){
    user.value = ''
    userAlert.textContent = ''
    userClear.style.display='none'
})


/* 
  需求: 点击pwdclear时,清空pwd的值,并隐藏
*/

pwdClear.addEventListener('click',function(){
    pwd.value = ''
    pwdAlert.textContent = ''
    pwdClear.style.display = 'none'
})